<?php

function getMenu($menu_name) {
    $ci =& get_instance();
    $ci->load->model('navigation/navigation_model');

    $lang = $ci->config->item('language_abbr');

    $menu_items = $ci->navigation_model->get_menu_by_name($menu_name, $lang);

    if (count($menu_items)>0)
    {
        $items = array();
        foreach ($menu_items as $menu_item)
        {
            $cur_uri = trailingslashit( uri_string() );
            $cur_uri = str_replace(leadingslashit($lang), '', $cur_uri);
            $cur_class = '';
            if ($menu_item->uri == '') {
                $the_uri =  trailingslashit( $menu_item->uri );
                if ($cur_uri==$the_uri) {
                    $cur_class = 'class="current"';
                }
            }
            else {
                $the_uri = trailingslashit( leadingslashit($menu_item->uri) );
                if (strpos($cur_uri, $the_uri)===0) {
                    $cur_class = 'class="current"';
                }
            }

//            echo 'the uri = ' . $the_uri . '<br/>';
//            echo 'cur uri = ' . $cur_uri . '<br/>';
//            echo '<hr/>';

            $items[] = anchor($menu_item->uri, $menu_item->title, $cur_class);
        }
        return ul( $items, array('class'=> 'menu-'.$menu_name) );
    }
}